import java.util.*;

public class P1003 {
    public static void main(String[] args) {
        Scanner l = new Scanner(System.in);
        String line = l.nextLine();
        Scanner sc = new Scanner(line);
//        Set<Integer> nums = new HashSet<>();
        Map<String,String> sea = new HashMap<>();
        List<String> list = new ArrayList<>();
        while(sc.hasNext()){
            String s = sc.next();
            int[] te = new int[26];
            for (char c : s.toCharArray()) {
                te[c-'a']++;
            }
            sea.put(Arrays.toString(te),s);
//            nums.add(s.length());
        }
        line = l.nextLine();
        sc = new Scanner(line);
        while(sc.hasNext()){
            String s = sc.next();
            int[] te = new int[26];
            for (char c : s.toCharArray()) {
                te[c-'a']++;
            }
            if(sea.containsKey(Arrays.toString(te)))
                list.add(sea.get(Arrays.toString(te)));
        }
        for (int i = 0; i < list.size(); i++) {
            if (i == list.size()-1)
                System.out.print(list.get(i));
            else
                System.out.print(list.get(i)+" ");
        }
    }
}
